# 指定CMake的最小版本
cmake_minimum_required(VERSION 3.5)
# 指定ROS 2软件包的名称
project(wit_ros)

#=======================================
# Compile setup (CATKIN, COLCON)
#=======================================
set(COMPILE_METHOD COLCON)

set(CMAKE_BUILD_TYPE RELEASE)

add_definitions(-O3)

#ROS2#
find_package(rclcpp QUIET)
if(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
  message(=============================================================)
  message("-- ROS2 Found. ROS2 Support is turned On!")
  message(=============================================================)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package_ros2.xml ${CMAKE_CURRENT_SOURCE_DIR}/package.xml COPYONLY)
  add_definitions(-DROS2_FOUND)
  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/package_ros2.xml ${CMAKE_CURRENT_SOURCE_DIR}/package.xml COPYONLY)

  set(CMAKE_CXX_STANDARD 14)

  # find dependencies
  # 寻找ament依赖
  find_package(ament_cmake REQUIRED)

  # 寻找ROS 2的依赖包
  find_package(rclpy REQUIRED)
  find_package(std_msgs REQUIRED) 

else(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")
  message(=============================================================)
  message("-- ROS2 Not Found. Ros2 Support is turned Off!")
  message(=============================================================)
endif(rclcpp_FOUND AND ${COMPILE_METHOD} STREQUAL "COLCON")

# 安装Python模块
ament_python_install_package(${PROJECT_NAME})

# 安装Python脚本
install(PROGRAMS
  wit_ros/wit_modbus_ros.py
  DESTINATION lib/${PROJECT_NAME}
)

# 安装其他文件，例如launch文件和配置文件等
install(DIRECTORY demo driver robot_para rviz
  DESTINATION share/${PROJECT_NAME}
)

# 声明ROS软件包的信息
ament_package()
